{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"Generate a voxel dataset by interpolating a scalar\n",
    "which is only known on a scattered set of points or mesh.\n",
    "Available interpolation kernels are: shepard, gaussian, voronoi, linear.\n",
    "The middle layer is the result of thresholding the volume\n",
    "between 0.3 and 0.4 and assigning it the new value of 0.9\"\"\"\n",
    "from vedo import *\n",
    "\n",
    "settings.default_backend = 'vtk'  # or k3d, ipyvtk, or vtk\n",
    "\n",
    "npts = 500                       # nr. of points of known scalar value\n",
    "coords = np.random.rand(npts, 3) # range is [0, 1]\n",
    "scals = np.abs(coords[:, 2])     # let the scalar be the z of point itself\n",
    "\n",
    "apts = Points(coords)\n",
    "apts.pointdata['scals'] = scals\n",
    "\n",
    "vol = apts.tovolume(kernel='shepard', radius=0.2, dims=(90,90,90))\n",
    "vol.cmap([\"tomato\", \"g\", \"b\"])   # set color transfer functions\n",
    "\n",
    "# this produces a hole in the histogram in the range [0.3, 0.4]'\n",
    "vol.threshold(above=0.3, below=0.4, replace=0.9) # replace voxel value in [vmin,vmax]\n",
    "\n",
    "plt = show(apts, vol, axes=1, elevation=-30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<tr>\n",
       "<td>\n",
       "<img src=''></img>\n",
       "</td>\n",
       "<td style='text-align: center; vertical-align: center;'><br/>\n",
       "<b> Points: &nbsp&nbsp</b><b><a href=\"https://vedo.embl.es/docs/vedo/pointcloud.html#Points\" target=\"_blank\">vedo.pointcloud.Points</a></b>\n",
       "<table>\n",
       "<tr><td><b> bounds </b> <br/> (x/y/z) </td><td>4.105e-3 ... 0.9990<br/>2.914e-4 ... 0.9981<br/>2.906e-3 ... 0.9915</td></tr>\n",
       "<tr><td><b> center of mass </b></td><td>(0.514, 0.500, 0.509)</td></tr>\n",
       "<tr><td><b> average size </b></td><td>0.478</td></tr>\n",
       "<tr><td><b> nr. points </b></td><td>500</td></tr>\n",
       "<tr><td><b> point data array </b></td><td>scals</td></tr>\n",
       "\n",
       "</table>\n",
       "</table>"
      ],
      "text/plain": [
       "<vedo.pointcloud.Points at 0x7414045ea630>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "apts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<vedo.plotter.Plotter at 0x7413c6b1acf0>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plt.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[7m\u001b[1mvedo version      : 2025.5.3+dev15  (https://vedo.embl.es)       \u001b[0m\n",
      "\u001b[1mvtk version       : 9.4.2\u001b[0m\n",
      "\u001b[1mnumpy version     : 2.1.3\u001b[0m\n",
      "\u001b[1mpython version    : 3.12.3 (main, Feb  4 2025, 14:48:35) [GCC 13.3.0]\u001b[0m\n",
      "\u001b[1mpython interpreter: /home/musy/vedoenv/bin/python3\u001b[0m\n",
      "\u001b[1minstallation point: /home/musy/Projects/vedo\u001b[0m\n",
      "\u001b[1msystem            : Linux 6.11.0-26-generic posix x86_64\u001b[0m\n",
      "\u001b[2mk3d version       : 2.16.1\u001b[0m\n",
      "\u001b[1m\u001b[33m💡 No input files? Try:\n",
      " vedo https://vedo.embl.es/examples/data/panther.stl.gz\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!vedo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
